package com.logistic.action;


import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.logistic.common.Excel;
import com.logistic.domain.ParaConfig;
import com.logistic.service.ParaConfigService;
import com.opensymphony.xwork2.ActionSupport;

public class ParaConfigAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private ParaConfigService paraConfigService;
	
	
	public String modify()
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = "key";
		ParaConfig pc = new ParaConfig();
		pc.setId(id);
		pc.setExchange_rate(this.getExchange_rate());
		pc.setUnit_price(this.getUnit_price());
		pc.setIntegral_ratio(this.getIntegral_ratio());
		pc.setFirst_price(this.getFirst_price());
		pc.setPresentIntegral(this.getPresentIntegral());
		pc.setPresentMoney(this.getPresentMoney());
		pc.setRecommendFlag(this.getRecommendFlag());
		
		paraConfigService.modify(pc);
		
		request.setAttribute("paraFlag","SUCCESS");
		
		return getParaConfig();
	}
	
	public String getParaConfig(){
		HttpServletRequest request = ServletActionContext.getRequest();
		
		String id = "key";
		ParaConfig pc = new ParaConfig();
		pc.setId(id);
		pc = paraConfigService.getParaConfigById(pc);
		
		request.setAttribute("pcTO", pc);
		
		return "paraConfigSuccess";
	}
	
	public void getParaTO()
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("pcId");
		String usaWarehouse = request.getParameter("usaWarehouse");
		//这是默认的一个  不针对口岸和美国地址   针对 推荐人送多少积分、送多少人民币
		if(id == null || "".equals(id)){
			id= "key";
			usaWarehouse = "CA";
		}
		ParaConfig pc = new ParaConfig();
		pc.setId(id);
		pc.setUsaWarehouse(usaWarehouse);
		pc = paraConfigService.getParaConfigById(pc);
		
		HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType( "text/html" ); 
	    response.setCharacterEncoding( "UTF-8" );
	     
	    try {
			response.getWriter().print("{success:true,unit_price:"+pc.getUnit_price()+",exchange_rate:"+pc.getExchange_rate()+",integral_ratio:"+pc.getIntegral_ratio()+",first_price:"+pc.getFirst_price()+
					",usaWarehouse:'"+pc.getUsaWarehouse()+"',usedIntegralFlag:'"+pc.getUsedIntegralFlag()+"',startWeightUsedIntegral:"+pc.getStartWeightUsedIntegral()+",startWeightNoFirst:"+pc.getStartWeightNoFirst()+"}");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	private String id;
	private String unit_price;
	private String exchange_rate;
	private String integral_ratio;
	private String first_price;
	private String  presentIntegral;
	private String presentMoney;
	private String recommendFlag;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getUnit_price() {
		return unit_price;
	}
	public void setUnit_price(String unitPrice) {
		unit_price = unitPrice;
	}
	public String getExchange_rate() {
		return exchange_rate;
	}
	public void setExchange_rate(String exchangeRate) {
		exchange_rate = exchangeRate;
	}
	public String getIntegral_ratio() {
		return integral_ratio;
	}
	public void setIntegral_ratio(String integralRatio) {
		integral_ratio = integralRatio;
	}
	public String getFirst_price() {
		return first_price;
	}
	public void setFirst_price(String firstPrice) {
		first_price = firstPrice;
	}
	
	public ParaConfigService getParaConfigService() {
		return paraConfigService;
	}
	public void setParaConfigService(ParaConfigService paraConfigService) {
		this.paraConfigService = paraConfigService;
	}
	
	public String getPresentIntegral() {
		return presentIntegral;
	}
	public void setPresentIntegral(String presentIntegral) {
		this.presentIntegral = presentIntegral;
	}
	public String getPresentMoney() {
		return presentMoney;
	}
	public void setPresentMoney(String presentMoney) {
		this.presentMoney = presentMoney;
	}
	public String getRecommendFlag() {
		return recommendFlag;
	}
	public void setRecommendFlag(String recommendFlag) {
		this.recommendFlag = recommendFlag;
	}

	

	
}
